/**
 * 
 */
package com.googlecode.xcarve.object;

import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.googlecode.xcarve.common.config.CarveConstances;

/**
 * @author xinyun.d
 * 2014-09-14
 */
public class RPCRequest implements Serializable{
	private static final long serialVersionUID = 1L;
	private static final AtomicLong SEQ_ID_BUILDER = new AtomicLong(0);
	private final long seqId;
	private boolean oneWay = false;
	private boolean async = false;
    private long timeout;
    private Class<?>	         service;
    private String               methodName;
    private Class<?>[]           parameterTypes;
    private Object[]             arguments;
    public transient static byte HEART_BEAT_ENVENT = (byte)1;  
    public byte event;
    
    public RPCRequest(){
    	this.seqId = SEQ_ID_BUILDER.incrementAndGet();
    }

	/**
	 * @return the oneWay
	 */
	public boolean isOneWay() {
		return oneWay;
	}

	/**
	 * @param oneWay the oneWay to set
	 */
	public void setOneWay(boolean oneWay) {
		this.oneWay = oneWay;
	}

	/**
	 * @return the timeout
	 */
	public long getTimeout() {
		return timeout;
	}

	/**
	 * @param timeout the timeout to set
	 */
	public void setTimeout(long timeout) {
		this.timeout = timeout;
	}

	/**
	 * @return the service
	 */
	public Class<?> getService() {
		return service;
	}

	/**
	 * @param service the service to set
	 */
	public void setService(Class<?> service) {
		this.service = service;
	}

	/**
	 * @return the methodName
	 */
	public String getMethodName() {
		return methodName;
	}

	/**
	 * @param methodName the methodName to set
	 */
	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}

	/**
	 * @return the parameterTypes
	 */
	public Class<?>[] getParameterTypes() {
		return parameterTypes;
	}

	/**
	 * @param parameterTypes the parameterTypes to set
	 */
	public void setParameterTypes(Class<?>[] parameterTypes) {
		this.parameterTypes = parameterTypes;
	}

	/**
	 * @return the arguments
	 */
	public Object[] getArguments() {
		return arguments;
	}

	/**
	 * @param arguments the arguments to set
	 */
	public void setArguments(Object[] arguments) {
		this.arguments = arguments;
	}

	 
	/**
	 * @return the seqId
	 */
	public long getSeqId() {
		return seqId;
	}
	
	/**
	 * @return the async
	 */
	public boolean isAsync() {
		return async;
	}

	/**
	 * @param async the async to set
	 */
	public void setAsync(boolean async) {
		this.async = async;
	}

	/**
	 * @return the envent
	 */
	public byte getEvent() {
		return event;
	}

	/**
	 * @param envent the envent to set
	 */
	public void setEvent(byte event) {
		this.event = event;
	}
	
	public boolean isHeartBeat(){
		return this.event == CarveConstances.HEART_REQUEST;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE);
	}
}
